classdef amcloop < handle
    %AMLOOP Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
        setchans %should this be it's own class? no, valrate, npoints need to be equal       
        getchans
        startpts
        endpts
        npoints
        pointrate
        %transfun
        isbuffered=0;
        data
        data2D
        plots
    end
    
    methods
        function pointvecs=points(aml)
            pointvecs=(aml.endpts-aml.startpts)'*linspace(0,1,aml.npoints)+aml.startpts'*ones(1,aml.npoints);
        end
        function vr=valrates(aml)
            vr=abs((aml.endpts-aml.startpts)/aml.npoints*aml.pointrate);
        end
        function ss=stepsize(aml)
            ss=abs((aml.endpts-aml.startpts)/aml.npoints);
        end
        function chans=allchans(aml)
            chans=[aml.setchans aml.getchans];
        end
        function r=ranges(aml)
            r=abs(aml.endpts-aml.startpts);
        end
        function setstepsize(aml,setchannum,val)
            if isnumeric(str2double(val)) && str2double(val)>0
                oldvalrate=aml.valrates(setchannum);
                aml.npoints=round(abs(aml.startpts(setchannum)-aml.endpts(setchannum))/val);
                setvalrate(setchannum,oldvalrate);
            else
                error('Input must be a positive number');
            end
        end
        function setvalrate(aml,setchannum,val)
            if isnumeric(str2double(val)) && str2double(val)>0
                aml.pointrate=round(abs(val/aml.stepsize(setchannum)));
            else
                error('Input must be a positive number');
            end
        end
        %% remove a setchan
        function rmsetchan(aml,setchannum)
            aml.setchans(setchannum)=[];
            aml.startpts(setchannum)=[];
            aml.endpts(setchannum)=[];
        end
        function addsetchan(aml)
            global amrack;
            aml.setchans(end+1)=amrack.rackchans(1);
            aml.startpts(end+1)=0;
            aml.endpts(end+1)=1;
        end
    end
    
end

